<template>
  <a-card :bordered="false">
    <!-- <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
                   <a-col :md="6" :sm="24">
                      <a-form-item label="">
                        <a-input v-model="queryParam.dto.parentId" placeholder=""/>
                      </a-form-item>
               </a-col>
          <a-col :md="6" :sm="24">
            <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
              <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
              <a-button style="margin-left: 8px" @click="resetSearchForm()">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div> -->

    <div class="table-operator">
      <a-button type="primary" icon="plus" @click="$refs.formHandle.add(null)">新建模块</a-button>
      <a-button style="margin-left: 8px" @click="resetSearchForm()">刷新</a-button>
    </div>
    <a-table
      :columns="columns"
      :dataSource="dataSource"
      ref="table"
      size="small"
      bordered
      rowKey="id"
      :data="loadData"
    >
      <span slot="action" slot-scope="text, record">
        <template>
          <a-tag color="orange" @click="handleEdit(record)" >编辑</a-tag>
          <a-tag color="red" @click="handleDelete(record)" >删除</a-tag>
          <a-tag color="green" @click="handleAdd(record)" v-if="record.attributes.type ===0" >新增</a-tag>
        </template>
      </span>

    </a-table>
    <form-handle ref="formHandle" @ok="handleOk" />
  </a-card>
</template>

<script>
import moment from 'moment'
import formHandle from './handle'
import { page, delByPk, batch } from '@/api/system/clientapi'
import { STable } from '@/components'
export default {
  name: 'TableList',
  components: {
    STable,
    formHandle
  },
  props: {
	  statusFilter: {
	    type: Function,
	    default: undefined
	  }
	},
  data () {
    return {
      mdl: {},
      advanced: false,
      dataSource: [],
      queryParam: {
            dto: {
            }
	  },
      columns: [
        {
         title: '名称',
         dataIndex: 'name'
        },
        {
         title: '接口地址',
         dataIndex: 'attributes.url'
        },
        {
         title: '接口标识',
         dataIndex: 'attributes.perms'
        },
        {
         title: '接口描述',
         dataIndex: 'apiDesc'
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: '250px',
          scopedSlots: { customRender: 'action' }
        }
      ]
      // loadData: parameter => {
      //     return page(Object.assign(parameter, this.queryParam)).then(response => {
      //       return response.res
      //     })
      // }
    }
  },
  created () {
    this.loadData()
  },
  methods: {
    handleDelete (record) {
        const that = this
        this.$confirm({
        title: '操作提醒',
        content: '确定要删除吗?',
        onOk () {
             delByPk({ id: record.id }).then(response => {
                 if (response.code === 0) {
                   that.$message.info(response.msg)
                 } else {
                   that.$message.error(response.msg)
                 }
                 that.handleOk()
             }).catch((response) => { that.$message.warn(response.message) })
        },
        onCancel () {}
       })
    },
    loadData () {
          page(this.queryParam).then(response => {
             this.dataSource = response.res.children
          })
    },
    handleAdd (record) {
      this.$refs.formHandle.add(record)
    },
    handleEdit (record) {
      this.$refs.formHandle.edit(record)
    },
    handleOk () {
      this.loadData()
    },
    resetSearchForm () {
      this.queryParam = {
        dto: { }
      }
      this.handleOk()
    }
}
}
</script>
